project( ruby )
cmake_minimum_required(VERSION 2.6)
find_package( Ruby REQUIRED )

# TODO
# on windows after compilation find bzfs.lib
# add linking to bzfs.lib on windows
# find patch executable

# change to svn checking
#file(MAKE_DIRECTORY bzflag)
#find_file(BZAPI bzfsAPI.h bzflag/include/)
#if (NOT BZAPI)
#    find_package( Subversion )
#    if (Subversion_FOUND)
#	execute_process( 
#	    COMMAND ${Subversion_SVN_EXECUTABLE}  co https://bzflag.svn.sourceforge.net/svnroot/bzflag/branches/v2_0branch/bzflag/
#	)
#    else(Subversion_FOUND)
#	message(SEND_ERROR "You must manually checkout bzflag v2_0branch into bzflag directory" )
#	return()
#    endif(Subversion_FOUND)
#endif(NOT BZAPI)
#set (BZAPI BZAPI-NOTFOUND CACHE FILEPATH "Cleared" FORCE)

execute_process( 
	    COMMAND ${RUBY_EXECUTABLE} apply_patches.rb
	)
	
if(WIN32)
find_library(BZLIB bzfs.lib bzflag/src/bzfs)
if (NOT BZLIB)
	message(SEND_ERROR "You must manually build bzfs.lib" )
	return()
endif(NOT BZLIB)
#set (BZLIB BZLIB-NOTFOUND CACHE FILEPATH "Cleared" FORCE)
endif(WIN32)

include_directories (${RUBY_INCLUDE_PATH}) 


set( SRCS
    src/bzRuby.cpp src/bzEvents.cpp src/Ruby.cpp 
)

set( HEADERS
    src/bzRuby.h src/bzEvents.h src/exceptions.h 
)


add_library(ruby MODULE ${SRCS} ${HEADERS} ruby.def)
if(WIN32)
	target_link_libraries( ruby ${BZLIB})

endif(WIN32)

target_link_libraries( ruby ${RUBY_LIBRARY})


